Ext.define('cp.view.form.MedicoBase',{
    extend: 'Ext.form.Panel',
   
    bodyPadding: '5px 5px 5px 5px', 
    bodyStyle: 'border: none',
    fieldDefaults: {
        labelWidth: 65,
        labelAlign: 'top'
    },
    initComponent: function(){
        this.action = this.actionUrl;
        var infoBasica = 
            {xtype: 'fieldset', defaultType: 'textfield', title: 'Básico', layout: 'column', items:
                [
                    {xtype: 'fieldset', defaultType: 'textfield', style: 'border: none', items:[
                        { fieldLabel: 'Apellido', name: 'apellido', allowBlank: false, 
                            minLength: 5, maxLength: 30, vtype: 'letrasEspacios' },
                        { fieldLabel: 'Nombre', name: 'nombre', 
                            allowBlank: false, minLength: 4, maxLength: 30, vtype: 'letrasEspacios' },
                        { fieldLabel: 'Domicilio', name: 'domicilio', allowBlank: false, minLength: 9,
                            maxLength: 200, vtype: 'domicilio' },
                        { fieldLabel:  'Nº Documento', name: 'dni', xtype: 'textfield', allowBlank: false,
                            minLength: 8, maxLength: 10, vtype: 'identificacion'},
                        { fieldLabel:  'Fecha de nacimiento', name: 'fechaNacimiento', xtype: 'datefield',
                            allowBlank: false, format: 'Y-m-d'}
                    ]}
                ]
              };
              
        var infoContacto =
            {xtype: 'fieldset', defaultType: 'textfield', style:'margin-left: 2px',height: '100%', title: 'Contacto', items:
                [   
                    { fieldLabel: 'Tel Casa', name: 'contacto-2', allowBlank: true, vtype: 'telefono'},
                    { fieldLabel: 'Tel Movil', name: 'contacto-3', allowBlank: true, vtype: 'telefono'},
                    { fieldLabel: 'Tel Trabajo', name: 'contacto-1', allowBlank: true, vtype: 'telefono'},
                    { fieldLabel: 'Tel Otro', name: 'contacto-4', allowBlank: true, vtype: 'telefono'},
                    { fieldLabel: 'E-mail', name: 'email', allowBlank: true, vtype: 'email'}
                ]
             };
             
        var infoMedico = 
            {xtype: 'fieldset', defaultType: 'textfield', style:'margin-left: 2px',title: 'Matriculas', items:
                        [   
                            { fieldLabel: 'Provincial', name: 'matProv', minLength: 5, maxLength: 6, allowBlank: false, vtype: 'identificacion'},
                            { fieldLabel: 'Nacional', name: 'matNac', minLength: 5, maxLength: 6, allowBlank: true, vtype: 'identificacion'}
                        ]
                    };

            
        
        this.items = [
            {
                itemId: 'campos',
                bodyStyle: 'border: none',
                layout: 'column',
                items: [
                    infoBasica, infoContacto, infoMedico
                ]
            }
        ];

        this.callParent(arguments);
    },
    submitForm: function(){
        if(this.getForm().isValid()){
            this.sendData();
        }else{
            Ext.create('cp.view.ui.AlertErr',{
                mensaje: 'El formulario contiene errores. Por favor, corrigalos, y vuelva a realizar la operación.'
                    }).showDialog();    
        }
    },
    sendData: function(){
        var me = this;
        this.getForm().submit({
            url: me.action,
            method: 'POST',
            success: function(form,action){
                Ext.create('cp.view.ui.AlertOk',{mensaje:action.result.msg}).showDialog();
                me.up('decoratorForm').close();
                Ext.ComponentQuery.query('gestionMedico')[0].getStore().load();                 
            },
            failure: function(form, action){
                Ext.create('cp.view.ui.AlertErr',{mensaje:action.result.msg}).showDialog();
            }
        });
    },
    populateObrasSociales: function(){
        return this;
    },
    populateEspecialidades: function(){
        return this;
    },
    renderChkGrp: function(anArray,aTitle,aCmp){
        var chkGrp = Ext.create('Ext.form.CheckboxGroup',{
            columns: 1,
            vertical: true,
            items: anArray
        });
        var fieldset = {xtype: 'fieldset', style:'margin-left: 2px',title: aTitle,items:[chkGrp]};
        this.getComponent(aCmp).add(fieldset);
        
    }
});